/* Copyright (C) 2011 clueless <clueless.mmopeon@gmail.com>
 *
 * This file is part of MMO Peon.
 *
 * MMO Peon is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MMO Peon is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MMO Peon.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __MMOPEON_PACKETS_H
#define __MMOPEON_PACKETS_H
#include <cstdint>
#include "commontypes.h"

typedef int (*SendFunction)(uint32_t size, uint8_t *buffer);
extern SendFunction SendPacket;

void ParseRecvPacket(struct PktWrapper *packet);
void ParseSendPacket(struct PktWrapper *packet);

struct PktContentWrapper
{
    uint32_t    contentId;
    uint8_t     data[1];    //dummy size
}__attribute__((packed));

struct PktWrapper
{
    uint32_t                    packetId;
    uint8_t                     flags[4];
    uint32_t                    size;
    struct PktContentWrapper    content;
}__attribute__((packed));

// 0x14
struct PktSpawnObject
{
    uint32_t    objectId;
    uint32_t    objectId2;  // Not sure
    uint32_t    objectType;
    char        name[32];
    uint8_t     unknown2[4];
    uint32_t    hp_max;
    uint32_t    power1_max;
    uint32_t    power2_max;
    uint8_t     unknown3[4];
    uint32_t    hp;
    uint32_t    power1;
    uint32_t    power2;
    uint8_t     unknown4[24];
    uint32_t    class1;
    uint32_t    class2;
    uint8_t     unknown5[4];
    uint32_t    level2;
    uint8_t     unknown6[72];
    RomCoords   coords;
    uint8_t     unknown7[20];

}__attribute__((packed));

// 0x15
struct PktDespawnObject
{
    uint32_t    objectId;
    uint8_t     objectType;
}__attribute__((packed));

// 0x17 Seems to be used for monsters etc
struct PktMoveObject1
{
    uint32_t    objectId;
    RomCoords   newCoords;
    float       unknown1;
    RomCoords   oldCoords;
    uint32_t    unknown2;
}__attribute__((packed));

// 0x4C
struct PktMoveObject2
{
    uint32_t    objectId;
    RomCoords   newCoords;
    float       unknown;
}__attribute__((packed));

// 0x23
struct PktMoveObject3
{
    uint32_t    objectId;
    RomCoords   newCoords;
    float       unknown1;
    float       unknown2;
    uint32_t    unknown3;
    float       unknown4;
}__attribute__((packed));

struct PktSomething
{
    uint32_t    objectId;
    uint32_t    unknown;
}__attribute__((packed));

struct PktSelectTarget
{
    uint8_t     unknown1[8];    // 58 02 00 00  0c 00 00 00
    uint32_t    objectId2;
    uint8_t     unknown2[4];    // a3 04 01 00
    uint32_t    objectId;
    uint8_t     unknown3[72];   //              4d 01 67 76  38 03 00 00  00 00 00 00
                                // 48 b4 f0 20  26 c7 6d 00  38 03 00 00  08 00 00 00
                                // 20 15 58 21  20 15 58 21  00 00 00 00  00 00 00 00
                                // 00 f6 bb 00  e0 a3 41 00  a0 d2 a1 00  08 00 00 00
                                // da bd 65 00  20 15 58 21  00 00 00 00
    uint32_t    objectIdSecond;
    uint8_t     unknown4[40];   // 00 e0 79 02  00 19 96 3c  71 ec 5f 00  11 00 00 00
                                // 08 00 00 00  54 eb 18 00  de ee 66 00  08 00 00 00
                                // 54 eb 18 00  89 03 00 00
}__attribute__((packed));

#endif

// 03E8 = 1000 = Human Male
// 03E9 = 1001 = Human Female
// 03EA = 1002 = Elf Male
// 03EB = 1003 = Elf Female
